<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>拦截器测试</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<jsp:include page="../../common.jsp"></jsp:include>
	
	<script type="text/javascript">
	function query01(){
	  $.ajax({
			   type: "post",
			   url: "listenerAndInterceptor/interceptorTest.htm",
			   data: "name=John&location=Boston",
			   dataType: "text",//预期服务器返回的数据类型

			   beforeSend: function(msg){
			       alert("发送请求之前调用:beforeSend"+msg)
			   },
			   /*
			   dataFilter: function(data, type){
			      alert("在请求成功之后调用:dataFilter。传入返回的数据以及dataType参数的值。并且必须返回新的数据（可能是处理过的）传递给success回调函数"+msg)
			       return data;
			   },	
			   	*/		   
			   success: function(data, textStatus){
				   alert( "当请求之后调用:success;"
				          +"data="+data
				          +";textStatus="+textStatus);
	           },
	           error: function(XMLHttpRequest,textStatus,errorThrown){ 
	               alert( "在请求出错时调用:error;"
	                      +"XMLHttpRequest="+XMLHttpRequest
	                      +";textStatus="+textStatus
	                      +";errorThrown="+errorThrown);
	           },
	           complete: function(XMLHttpRequest, textStatus){
	               alert( "当请求完成之后调用这个函数，无论成功或失败:complete;"
	                      +"XMLHttpRequest="+ XMLHttpRequest
	                      +";textStatus="+textStatus);
	           },
	           //根据状态码，执行方法
	           statusCode: {
	             360: function() {
                       alert('360');
                   },
                 400: function() {
                       alert('page not found');
                   }  
               }	           	           	     	           	           
             });
                         
	}
	$("#btn").ajaxError(function(event,request, settings){
        $(this).append("<li>出错页面:" + settings.url + "</li>");
     });
	
	
	
	</script>
  </head>  
  <body>
     <a id="btn" href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="query01()">查询(此方法被拦截器拦截，并返回错误到页面)</a>    
   </body>
 </html>
